package com.jiangyg.mall.order.controller;

import com.jiangyg.mall.core.support.restful.Pagination;
import com.jiangyg.mall.core.support.restful.Result;
import com.jiangyg.mall.order.dto.RefundInfoDTO;
import com.jiangyg.mall.order.service.RefundInfoService;
import com.jiangyg.mall.order.vo.RefundInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 类描述：退款信息控制器
 *
 * @author jiangyg
 * @version email@jiangyg.com
 * @date 2021-10-30 07:36:28
 */
@RestController
@RequestMapping("/order/refundInfo")
public class RefundInfoController {

    /**
     * 退款信息接口
     */
    private final RefundInfoService refundInfoService;

    @Autowired
    public RefundInfoController(RefundInfoService refundInfoService) {
        this.refundInfoService = refundInfoService;
    }

    /**
     * 功能描述：退款信息分页查询
     *
     * @param request    请求
     * @param pagination 分页参数
     * @return 返回分页退款信息
     */
    @ResponseBody
    @PostMapping("/select")
    public Result<Pagination<RefundInfoVO>> select(HttpServletRequest request, @RequestBody Pagination<RefundInfoVO> pagination) throws Exception {
        return Result.ok(refundInfoService.selectPagination(pagination));
    }

    /**
     * 功能描述：保存或者修改退款信息
     *
     * @param request 请求
     * @param dto     退款信息
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/save")
    public Result<Object> save(HttpServletRequest request, @RequestBody @Validated RefundInfoDTO dto) throws Exception {
        return Result.saveOrUpdate(refundInfoService.saveOrUpdate(dto));
    }

    /**
     * 功能描述：根据ID获取退款信息
     *
     * @param request 请求
     * @param refundInfoId  退款信息ID
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/info")
    public Result<RefundInfoVO> info(HttpServletRequest request, @RequestParam(name = "refundInfoId") Long refundInfoId) throws Exception {
        return Result.ok(refundInfoService.selectById(refundInfoId));
    }

    /**
     * 功能描述：删除退款信息
     *
     * @param request 请求
     * @param refundInfoIds 批量删除的退款信息ID
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/delete")
    public Result<Object> delete(HttpServletRequest request, @RequestParam(name = "refundInfoIds") List<Long> refundInfoIds) {
        return Result.delete(refundInfoService.delete(refundInfoIds));
    }

}
